import React, { Component } from 'react';
import { Button, View, Alert, DeviceEventEmitter  } from 'react-native';
import ToastAndroid from './ToastAndorid'
import ToastExample from './ToastExample'
import DownloadAndroid from './Download'

let onButtonPress = () => {
    // 警告框
    // Alert.alert("Button has been pressed!");
    ToastAndroid.show("Button has been pressed!", ToastAndroid.SHORT);
};

export default class Toast extends Component {
    componentWillMount(){
        DeviceEventEmitter.addListener('download', function (params) {
            let json = JSON.stringify(params);
            let data = JSON.parse(json);
            ToastAndroid.show(data.progress+"", ToastAndroid.SHORT);
        });
    }
    render() {
        return(
            <View style={{width: 300, height: 200, backgroundColor: 'powderblue'}}>
                <Button
                    title={"show Toast"}
                    color={"#841584"}
                    accessibilityLabel={"显示吐司"}
                    // onPress={onButtonPress()}
                    onPress={() => {
                        // 显示吐司
                        // ToastAndroid.show("Button has been pressed!", ToastAndroid.SHORT);
                        // ToastExample.show("Button has been pressed!", ToastExample.SHORT);

                        // 回调
                        // DownloadAndroid.download(
                        //     (msg) => {
                        //         ToastAndroid.show("错误："+msg, ToastAndroid.SHORT);
                        //     },
                        //     (num) => {
                        //         ToastAndroid.show("进度：" + num, ToastAndroid.SHORT);
                        //     }
                        // );

                        // 下载
                        DownloadAndroid.downloadFile();
                    }}
                />
            </View>
        )
    }
}